package com.feimt.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.feimt.common.BaceContent;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;

@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {
    /*新增触发*/
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("insert:{}",metaObject);
        metaObject.setValue("createTime",LocalDateTime.now());
        metaObject.setValue("updateTime",LocalDateTime.now());
        metaObject.setValue("createUser",BaceContent.getThreadLocal());
        metaObject.setValue("updateUser",BaceContent.getThreadLocal());
    }
    /*修改触发*/
    @Override
    public void updateFill(MetaObject metaObject) {
        System.err.println("updateFill线程ID:"+Thread.currentThread().getId());
        log.info("update:{}",metaObject);
        metaObject.setValue("updateTime",LocalDateTime.now());
        metaObject.setValue("updateUser", BaceContent.getThreadLocal());
    }
}
